#include "radioviewcell.h"
#include "ui_radioviewcell.h"
#include "radiomodel.h"
#include "BLL/radioBLl/radiobll.h"
#include "radioplaylistmodel.h"
#include "playEngine/ezvoiceplayermanager.h"

RadioViewCell::RadioViewCell(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RadioViewCell)
{
    _radio = 0;
    ui->setupUi(this);
    connect(ui->backBt,SIGNAL(clicked()),this,SLOT(onClicked()));
}

RadioViewCell::~RadioViewCell()
{
    if(_radio){
        _radio->Release();
    }
    delete ui;
}
RadioModel* RadioViewCell::radio() const
{
    return _radio;
}

void RadioViewCell::setRadio(RadioModel *value)
{
    if(value){
        value->Retain();
    }
    if(_radio){
        _radio->Release();
    }
    _radio = value;

    reView();
}

void RadioViewCell::reView()
{
    if(_radio){
        ui->backImageView->loadImageWithUrl(_radio->getImgurlWithSize(150));
        ui->titleLabel->setText(_radio->getFmname());
    }else{
        ui->backImageView->setImageWithPixmap(QPixmap());
        ui->titleLabel->setText("");
    }
}

void RadioViewCell::onClicked()
{
//    qDebug() << "clicked";
    if(_radio==0){
        return;
    }
    RadioPlayListModel *playList = RadioBll::playListWithRadio(_radio);
    EZVoicePlayerManager::defaultManager()->setPlayList(playList);
    EZVoicePlayerManager::defaultManager()->playCurrent();
}
